<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html" ; charset="utf-8" />
    <title>宏宇教育信息采集</title>
    <link href="./index.css" rel="stylesheet" type="text/css" />
  </head>

  <style>
    /* .id-front .el-upload--picture-card, .id-back .el-upload--picture-card, .cun1 .el-upload--picture-card, .cun2 .el-upload--picture-card, .cun1 .el-upload--picture-card, .cun1 .el-upload--picture-card {
        display: none;
    } */
    .hide .el-upload--picture-card {
      display: none;
    }
    .box-card {
      margin: 20px 0;
    }
  </style>

  <body>
    <div id="app">
      <app-refund-base-information
        v-if="typeName === 'fenqi'"
        :type="type"
        ref="baseInfo"
      ></app-refund-base-information>
      <app-base-information
        v-else
        :file-map="fileList"
        :type="type"
        ref="baseInfo"
      ></app-base-information>
      <template v-if="typeName !== 'fenqi'">
        <app-education-level
          ref="educationLevel1"
          :type="type"
          :file-map="fileList"
          :levelnum="1"
          :level-list="levelList"
        ></app-education-level>
        <app-education-level
          ref="educationLevel2"
          :type="type"
          :file-map="fileList"
          :levelnum="2"
          :level-list="levelList"
        ></app-education-level>
        <app-certificate
          :type="type"
          :file-map="fileList"
          ref="certificate"
        ></app-certificate>
      </template>
      <app-education
        :type="type"
        :level-list="levelList"
        v-if="isEducation"
        ref="education"
      ></app-education>
      <app-occupation
        :type="type"
        v-if="isOccupation"
        ref="occupation"
      ></app-occupation>
      <app-title :type="type" v-if="isTitle" ref="title"></app-title>
      <app-train :type="type" v-if="isTrain" ref="train"></app-train>
      <app-cost-information
        :type="type"
        :from="from"
        :fee-len="feeLen"
        ref="costInfo"
        :title="costTitle"
      ></app-cost-information>
      <app-refund-info
        :type="type"
        ref="refundInfo"
        v-if="typeName  === 'tuikuan'"
      ></app-refund-info>
      <app-pay-voucher :file-map="fileList"></app-pay-voucher>
      <app-resolve-info
        v-if="isShowResolve"
        :from="from"
        ref="resolveInfo"
      ></app-resolve-info>
      <el-row>
        <el-col style="display: flex; justify-content: center">
          <template v-if="from">
            <el-button
              :disabled="isSubmit"
              @click="handleValid('check')"
              type="primary"
              >审核通过</el-button
            >
            <el-button
              :disabled="isSubmit"
              @click="handleValid('resolve')"
              type="primary"
              >驳回</el-button
            >
          </template>
          <template v-else>
            <el-button @click="handleBack('action')" type="primary"
              >返回</el-button
            >
          </template>
        </el-col>
      </el-row>
    </div>

    <script src="../../../js/jquery.js"></script>
    <script src="../../../js/common.js"></script>
    <script src="../../../js/vue.js"></script>
    <script src="../../../js/element.js"></script>
    <script src="./components/RefundBaseInfo.js"></script>
    <script src="./components/BaseInformation.js"></script>
    <script src="./components/EducationLevel.js"></script>
    <script src="./components/Certificate.js"></script>
    <script src="./components/Education.js"></script>
    <script src="./components/Occupation.js"></script>
    <script src="./components/Title.js"></script>
    <script src="./components/Train.js"></script>
    <script src="./components/CostInformation.js"></script>
    <script src="./components/ResolveInfo.js"></script>
    <script src="./components/PayVoucher.js"></script>
    <script src="./components/RefundInfo.js"></script>

    <script>
      const app = new Vue({
        el: "#app",
        created() {
          this.infoName = getQuery("trainType");
          this.from = getQuery("from");
          this.typeName = getQuery("action");
        },
        mounted() {
          this.getPageTitle();
          this.getEducationOption();
          // 如果是通过操作进入当前页面，就调用获取的接口
          this.pageNumber = Number(getQuery("pageNumber"));

          (this.type = getQuery("type")) && this.getStudentInfo();
        },
        data: {
          // 点击返回把当前查询页面页码返回
          pageNumber: 0,
          // 是否点击过保存或者驳回
          isSubmit: false,
          levelList: [],
          // 当前页面的名称
          infoName: "",
          typeName: "",
          type: "",
          from: "",
          feeLen: 4,
          oldData: {},
          action: "",
          refundBaseInfoMap: new Map([
            ["name", "name"],
            ["phoneNum", "phone"],
            ["idNo", "idNum"],
            ["sex", "gender"],
          ]),
          baseInfoMap: new Map([
            ["name", "name"],
            ["phoneNum", "phone"],
            ["idNo", "idNum"],
            ["nation", "nationality"],
            ["sex", "gender"],
            ["birthday", "birthday"],
            ["address", "address"],
            ["email", "email"],
            ["qqNumber", "qq"],
            ["workAdress", "work"],
          ]),
          educationLevel: new Map([
            ["major", "discipline"],
            ["educationName", "level"],
            ["studyMode", "path"],
            ["graduateSchool", "school"],
            ["graduateTime", "time"],
            ["certificateNumber", "cerNum"],
          ]),
          educationMap: new Map([
            ["studyMode", "pathLabel"],
            ["educationName", "levelLabel"],
            ["schoolName", "schoolLabel"],
            ["majorName", "discipline"],
            ["batch", "batch"],
          ]),
          occupationKeys: [
            "professionalTypes",
            "majorName",
            "batch",
            "applyExplain",
          ],
          titleKeys: [
            "professionalLevel",
            "professionalSeries",
            "majorName",
            "batch",
          ],
          trainKeys: [
            "applyProject",
            "examCourse",
            "classs",
            "applyAssist",
            "startDate",
            "endDate",
            "batch",
          ],
          feesMap: new Map([
            ["stage", "stage"],
            ["amount", "fee"],
            ["term", "feeDate"],
            ["flag", "isFee"],
            ["receiptStatus", "receipt"],
            ["receiptNo", "receiptNum"],
          ]),
          feeMap: new Map([
            ["otherFee", "otherFee"],
            ["paidinFee", "training"],
            ["explains", "description"],
            ["allFee", "total"],
            ["preferentialFee", "discount"],
            ["realPayFee", "paid"],
          ]),
          fileList: [],
        },
        computed: {
          isEducation() {
            return this.infoName === "education";
          },
          isOccupation() {
            return this.infoName === "occupation";
          },
          isTitle() {
            return this.infoName === "title";
          },
          isTrain() {
            return this.infoName === "train";
          },
          isShowResolve() {
            return this.from !== "bc";
          },
          costTitle() {
            const map = {
              education: "学历",
              occupation: "职业",
              title: "职称",
              train: "培训",
            };
            return map[this.infoName];
          },
        },
        methods: {
          handleBack(name) {
            var backPath =
              getQuery(name) === "caiwu"
                ? "../store/moneySearch.html"
                : "../trade/tradeSearch.html";
            window.location.href = backPath + `?pageNumber=${this.pageNumber}`;
          },
          getPageTitle() {
            // 根据查询字符串info，来判断显示哪个报考信息
            const from = getQuery("from");
            switch (from) {
              case "jiaowu":
                localStorage.setItem("name", "教务管理/教务信息管理/审核");
                break;
              case "caiwu":
                localStorage.setItem("name", "财务管理/缴费信息管理/审核");
                break;
              case "fenqi":
                localStorage.setItem("name", "学生管理/分期缴费信息查询/修改");
                break;
            }
          },
          getRefs(key = "") {
            const {
              baseInfo = {},
              educationLevel1 = {},
              educationLevel2 = {},
              certificate = {},
              refundInfo = {},
              costInfo = {},
              resolveInfo = {},
              education = {},
              occupation = {},
              title = {},
              train = {},
            } = this.$refs;

            return {
              baseInfo: baseInfo[key],
              educationLevel1: educationLevel1[key],
              educationLevel2: educationLevel2[key],
              certificate: certificate[key],
              refundInfo: refundInfo[key],
              costInfo: costInfo[key],
              resolveInfo: resolveInfo[key],
              education: education[key],
              occupation: occupation[key],
              title: title[key],
              train: train[key],
            };
          },
          handleValid(action) {
            this.action = action;
            const { costInfo, resolveInfo } = this.getRefs("formData");

            const reasonUrl =
              this.from === "caiwu"
                ? baseUrl + "studentInfo/caiwuCheck"
                : baseUrl + "studentInfo/jiaowuCheck";

            // 报考流程
            let commitFlag = this.from === "caiwu" ? 4 : 6;
            // 退款流程
            if (this.typeName === "tuikuan" || this.typeName === "fenqi") {
              commitFlag = this.from === "caiwu" ? 10 : 2;
            }

            if (action === "resolve") {
              if (!resolveInfo.denyReason) {
                this.$message.error("请输入驳回消息");
                return;
              }
              commitFlag = this.from === "caiwu" ? 3 : 5;
            } else {
              if (this.from === "caiwu") {
                if (
                  !costInfo.isChange ||
                  costInfo.fees.every((item) => !item.isFee)
                ) {
                  this.$message.error("请确认是否缴费");
                  return;
                }
                const isPayedFee = costInfo.fees
                  .filter((item) => item.isFee)
                  .reduce(
                    ({ fee: feePrev }, { fee: feeNext }) => {
                      return { fee: Number(feePrev) + Number(feeNext) };
                    },
                    { fee: 0 }
                  );
                const feeTotal = isPayedFee.fee + Number(costInfo.otherFee);

                if (feeTotal != costInfo.paid) {
                  this.$message.error(
                    "选择是的金额与实缴金额一致，请确认是否缴费"
                  );
                  return;
                }
              }
            }

            const data = {
              studyId: getQuery("studyId"),
              userId: JSON.parse(localStorage.getItem("userInfo")).userId,
              checkType: action === "resolve" ? 2 : 1,
              denyReason: action === "resolve" ? resolveInfo.denyReason : "",
              commitFlag,
            };

            const msg =
              action !== "resolve"
                ? "该信息是否已符合审核标准,确认审核通过?"
                : "是否要驳回？";
            this.$confirm(msg, "温馨提示", {
              confirmButtonText: "是",
              cancelButtonText: "否",
              type: "warning",
            })
              .then(() => {
                $.ajax({
                  url: reasonUrl,
                  method: "post",
                  headers: {
                    Authorization: JSON.parse(localStorage.getItem("userInfo"))
                      .token,
                  },
                  data: data,
                  success: (res) => {
                    if (res.code === 200) {
                      this.isSubmit = true;
                      if (action !== "resolve") {
                        this.saveFee(commitFlag);
                      } else {
                        this.$message({
                          type: "success",
                          message: "驳回成功!",
                        });
                        this.handleBack("from");
                      }
                    }
                  },
                });
              })
              .catch(() => {});
          },
          saveFee(commitFlag) {
            const { costInfo } = this.getRefs("formData");
            // const costInfo = this.$refs.costInfo.formData;
            this.oldData.fees.map((item, index) => {
              item.commitFlag = commitFlag;
              if (commitFlag == 4 || this.typeName === "fenqi") {
                item.flag = costInfo.fees[index].isFee;
              }
              delete item.createDate;
            });

            $.ajax({
              url: baseUrl + "studentInfo/updateFee",
              method: "post",
              headers: {
                Authorization: JSON.parse(localStorage.getItem("userInfo"))
                  .token,
              },
              contentType: "application/json",
              data: JSON.stringify(this.oldData.fees),
              success: (data) => {
                this.$message({
                  type: "success",
                  message: "审核成功!",
                });
                this.handleBack("from");
              },
            });
          },
          getStudentInfo() {
            const trainType = getQuery("trainType");
            const idNo = getQuery("idNo");
            const studyId = getQuery("studyId");

            const {
              baseInfo,
              educationLevel1: educationLevelInfo,
              educationLevel2: educationLevelInfo2,
              certificate,
              refundInfo,
              costInfo,
              resolveInfo,
              education,
              occupation,
              title,
              train,
            } = this.getRefs("formData");

            $.ajax({
              url: baseUrl + "studentInfo/getStudentInfo",
              method: "get",
              headers: {
                Authorization: JSON.parse(localStorage.getItem("userInfo"))
                  .token,
              },
              data: {
                idNo,
                trainType,
                studyId,
              },
              success: (data) => {
                this.oldData = data;
                // this.id = data.student.id;
                // baseInfo.id = data.student.id;
                if (this.typeName === "fenqi") {
                  for (item of this.refundBaseInfoMap) {
                    baseInfo[item[1]] = data.student[item[0]];
                  }
                } else {
                  for (item of this.baseInfoMap) {
                    baseInfo[item[1]] = data.student[item[0]];
                  }

                  for (item of this.educationLevel) {
                    educationLevelInfo[item[1]] = data.student[item[0]];
                    educationLevelInfo2[item[1]] = data.student[item[0] + "2"];
                  }
                }

                if (education) {
                  for (item of this.educationMap) {
                    education[item[1]] = data.studentEducation[item[0]];
                  }
                }

                if (occupation) {
                  for (item of this.occupationKeys) {
                    occupation[item] = data.studentOccupation[item];
                  }
                }

                if (title) {
                  for (item of this.titleKeys) {
                    title[item] = data.studentTitle[item];
                  }
                }

                if (train) {
                  for (item of this.trainKeys) {
                    if (item === "examCourse") {
                      train[item] = data.studentTrain[item].split(",");
                    } else {
                      train[item] = data.studentTrain[item];
                    }
                  }
                }
                this.feeLen = data.fees.length;
                this.$nextTick(() => {
                  data.fees.map((feeItem, index) => {
                    refundInfo &&
                      (refundInfo.refundableFee = feeItem.refundableFee);
                    refundInfo && (refundInfo.deductFee = feeItem.deductFee);
                    refundInfo &&
                      (refundInfo.realRefundFee = feeItem.realRefundFee);
                    const performanceFlag = +feeItem.performanceFlag
                      ? +feeItem.performanceFlag
                      : "";
                    refundInfo &&
                      (refundInfo.performanceFlag = performanceFlag);
                    refundInfo && (refundInfo.refundInfo = feeItem.refundInfo);
                    refundInfo && (refundInfo.payee = feeItem.payee);

                    costInfo.otherName = feeItem.otherName;

                    for (item of this.feeMap) {
                      costInfo[item[1]] = feeItem[item[0]];
                    }

                    for (feesItem of this.feesMap) {
                      if (["stage", "fee"].includes(feesItem[1])) {
                        costInfo.fees[index][feesItem[1]] =
                          feeItem[feesItem[0]] || undefined;
                      } else {
                        costInfo.fees[index][feesItem[1]] =
                          feeItem[feesItem[0]];
                      }
                    }

                    resolveInfo.denyReason = feeItem.denyReason;
                  });
                });
                this.fileList = data.studentCards;
              },
            });
          },
          getEducationOption() {
            $.ajax({
              url: baseUrl + "education/queryEducationList",
              async: false,
              method: "Post",
              headers: {
                Authorization: JSON.parse(localStorage.getItem("userInfo"))
                  .token,
              },
              success: (data) => {
                this.levelList = data;
                console.log(`this.levelList`, this.levelList);
              },
            });
          },
        },
      });
    </script>
  </body>
</html>
